<script setup>
import {readExcel} from "@/utils/readExcel.js";
import {ref} from "vue"
import {exportWeek} from "@/views/Export/exportWeek.js";
const fileList = ref([])

function handleRemove() {
  fileList.value = []
}

const loading = ref(false)
async function exportReport(file){
  try{
    fileList.value = []
    loading.value = true
    let dataArr = await readExcel(file)
    await exportWeek(dataArr)
  }catch (e){
    console.log(e)
    ElMessage.error(e)
  }finally {
    loading.value = false
  }
}
</script>

<template>
<div class="box">
  <el-upload
    v-loading="loading"
    v-model:file-list="fileList"
    class="upload-demo"
    drag
    action=""
    :on-remove="handleRemove"
    :before-upload="exportReport"
  >
    <div class="el-upload__text">
      将Excel文件拖拽至此或 <em>点击上传</em>
    </div>
  </el-upload>
</div>
</template>

<style scoped>
.box{
  width: 50vw;
  margin: 30vh auto;
}

.upload-demo{
  width: 100%;
  height: 100%;
}
</style>